package com.pachong.android.framework.commonui;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;

import com.pachong.android.frameworkbase.dialog.AlertDialogFragment;


/**
 * 系統dialog 对话框
 * 用户app在后台接收消息之后弹出的框框
 *
 * 接口待完善
 *
 * @Author: PV
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 20110--26
 * @Version: 1.0.0
 */
public class SystemDialogActivity extends AppCompatActivity implements DialogInterface.OnDismissListener {

    AlertDialogFragment fragment;

    public static void start(Activity context, String title, String message) {
        Intent intent = new Intent(context, SystemDialogActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("message", message);
        context.startActivity(intent);
    }

    String title;
    String message;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        title = getIntent().getStringExtra("title");
        message = getIntent().getStringExtra("message");
    }

    @Override
    protected void onResumeFragments() {
        super.onResumeFragments();
        fragment = new AlertDialogFragment();
        if (!TextUtils.isEmpty(title)) {
            fragment.setTitle(title);
        }

        if (!TextUtils.isEmpty(message)) {
            fragment.setMessage(message);
        }

        fragment.setPositiveButton("确定", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fragment.dismissAllowingStateLoss();
            }
        });

      /*  fragment.setNegativeButton("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fragment.dismissAllowingStateLoss();
            }
        });
*/

        fragment.show(getSupportFragmentManager());
    }


    @Override
    public void onDismiss(final DialogInterface dialog) {
        finish();
    }
}
